import type { FieldRule } from 'vant'

// 提供校验规则
const userNameRules: FieldRule[] = [
  { required: true, message: '请输入用户名' },
  { pattern: /^[\w-]{4,16}$/, message: '4-16个字符，字母、数字、下划线、减号' }
]

const passwordRules: FieldRule[] = [
  { required: true, message: '请输入密码' },
  { pattern: /^[\w-]{4,16}$/, message: '4-16个字符，字母、数字、下划线、减号' }
]

const codeRules: FieldRule[] = [
  { required: true, message: '请输入密码' },
  {
    pattern: /^\w{4,12}$/, // 4-12 位字母、数字或下划线
    message: '密码必须是4-12个字符'
  }
]

const nameRules: FieldRule[] = [
  { required: true, message: '请输入真实姓名' },
  { pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/, message: '中文字符2-16个字符' }
]

const idCardRules: FieldRule[] = [
  { required: true, message: '请输入身份证号' },
  {
    pattern: /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '身份证号格式不正确'
  }
]

export { userNameRules, passwordRules, codeRules, nameRules, idCardRules }
